" Common things.
"
syntax      on
filetype    off
filetype    plugin indent on
filetype    plugin on
set         nocompatible
set         rtp+=/usr/lib/python3.6/site-packages/powerline/bindings/vim/ " Powerline.
set         laststatus=2 " Powerline.
set         t_Co=256 " Powerline.
set         number
" set         relativenumber
set         clipboard=unnamedplus
set         tabstop=4
set         shiftwidth=4
set         expandtab
set         incsearch
set         ignorecase
set         hidden
set         shortmess+=I
set         directory=$HOME/.vim/backups/
set         undofile
set         undodir=$HOME/.vim/undo/
set         t_Co=256
set         term=xterm-256color
set         colorcolumn=80

" [airline] Always show numbered listed of buffers.
"
let         g:airline#extensions#tabline#enabled=1
let         g:airline#extensions#tabline#buffer_nr_show=1

" [airline] Remove pause after leaving insert mode.
set         timeoutlen=1000 ttimeoutlen=0

" [ctrlp] Don't split when opening a new file.
"
let         g:ctrlp_open_new_file = 'r'

" If forgot to sudoedit.
"
command!    -nargs=0 Sw w !sudo tee % > /dev/null


" Vundle plugins.
"
set         rtp+=~/.vim/bundle/Vundle.vim
call        vundle#begin()
Plugin      'VundleVim/Vundle.vim'
"Plugin      'Valloric/YouCompleteMe'
Plugin      'vim-airline/vim-airline'
Plugin      'vim-airline/vim-airline-themes'
Plugin      'ying17zi/vim-live-latex-preview'
Plugin      'shime/vim-livedown'
Plugin      'wakatime/vim-wakatime'
Plugin      'jiangmiao/auto-pairs'
Plugin      'easymotion/vim-easymotion'
Plugin      'tpope/vim-surround'
Plugin      'tpope/vim-commentary'
Plugin      'kien/ctrlp.vim'
Plugin      'vim-syntastic/syntastic'
Plugin      'notpratheek/vim-luna'
Plugin      'Shougo/neocomplete.vim'
Plugin      'Shougo/neosnippet.vim'
Plugin      'Shougo/neosnippet-snippets'
Plugin      'koryschneider/vim-trim'
Plugin      'https://notabug.org/SylvieLorxu/vim-friendlyremark.git'
Plugin      'junegunn/goyo.vim'
Plugin      'junegunn/limelight.vim'
call        vundle#end()



" Theming.
"
syntax      enable
colorscheme luna-term
let         g:airline_theme='luna'
" let         g:airline_powerline_fonts=0
" set         cursorline


" Remappings.
"
map         <F2> :bprevious<CR>
map         <F3> :bnext<CR>
map         <F4> :buffers<CR>
map         <F5> :%y+<CR>
map         <F6> :echo @%<CR>
map         <F7> :pwd<CR>
map         <F12> :bd!<CR>

" Just because <F1>'s help buffer annoys when accidentally opened.
"
map         <F1> <Nop>
inoremap    <F1> <Esc>
vnoremap    <F1> <Esc>

nnoremap    <C-J> <C-W><C-J>
nnoremap    <C-K> <C-W><C-K>
nnoremap    <C-L> <C-W><C-L>
nnoremap    <C-H> <C-W><C-H>

let         g:mapleader=','
map         <Leader>g :Goyo<CR>
map         <Leader> <Plug>(easymotion-prefix)
map         <F8> :setlocal spell! spelllang=en_us<CR>
map         <C-F8> :setlocal spell! spelllang=ru_ru<CR>
map         <F9> :set colorcolumn=80<CR>
map         <C-F9> :set colorcolumn=0<CR>


" Scripts things.
"
imap <F10> <Esc>:w<CR>:!clear;./%<CR>
map  <F10> <Esc>:w<CR>:!clear;./%<CR>


" Syntastic settings
"
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*

" To open location list type ":lopen", to update it type ":Errors"
" To jump to next/prev location type ":lnext", ":lprevious"
"
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 0
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
let g:syntastic_python_checkers = ['pep8']
let g:syntastic_cpp_compiler = 'clang++'
let g:syntastic_cpp_compiler_options = ' -std=c++17 -stdlib=libc++'

" [neocomplete] Use tab to select a completion, Ctrl+K to expand a snippet,
" Ctrl+H to close Neocomplete.
"
let g:neocomplete#enable_at_startup = 1
imap <C-k>     <Plug>(neosnippet_expand_or_jump)
smap <C-k>     <Plug>(neosnippet_expand_or_jump)
xmap <C-k>     <Plug>(neosnippet_expand_target)
imap <expr><TAB>
 \ pumvisible() ? "\<C-n>" :
 \ neosnippet#expandable_or_jumpable() ?
 \    "\<Plug>(neosnippet_expand_or_jump)" : "\<TAB>"
inoremap <expr><C-h> pumvisible() ? "\<C-y>" : "\<C-h>"


" Protect large files from sourcing and other overhead.
" Files become read only
if !exists("my_auto_commands_loaded")
  let my_auto_commands_loaded = 1
  " Large files are > 10M
  " Set options:
  " eventignore+=FileType (no syntax highlighting etc
  " assumes FileType always on)
  " noswapfile (save copy of file)
  " bufhidden=unload (save memory when other file is viewed)
  " buftype=nowrite (file is read-only)
  " undolevels=-1 (no undo possible)
  let g:LargeFile = 1024 * 1024 * 10
  augroup LargeFile
    autocmd BufReadPre * let f=expand("<afile>") | if getfsize(f) > g:LargeFile | set eventignore+=FileType | setlocal noswapfile bufhidden=unload buftype=nowrite undolevels=-1 | else | set eventignore-=FileType | endif
    augroup END
  endif

"""My snippets"""

inoremap    ;gm <++>
inoremap    <C-j> <Esc>/<++><CR>"_d4li


" LaTeX things.
"
autocmd     BufNewFile,BufRead *.tex inoremap ;s<Space> \section{}<CR><Tab><++><Esc>?{<CR>a
autocmd     BufNewFile,BufRead *.tex inoremap ;ss<Space> \subsection{}<CR><Tab><++><Esc>?{<CR>a
autocmd     BufNewFile,BufRead *.tex inoremap ;sss<Space> \subsubsection{}<CR><Tab><++><Esc>?{<CR>a
autocmd     BufNewFile,BufRead *.tex inoremap ;enu \begin{enumerate}<Esc>o\end{enumerate}<CR><CR><++><Esc>kkko\item
autocmd     BufNewFile,BufRead *.tex inoremap ;ite \begin{itemize}<Esc>o\end{itemize}<CR><CR><++><Esc>kkko\item
autocmd     BufNewFile,BufRead *.tex inoremap ;li \item
autocmd     BufNewFile,BufRead *.tex inoremap ;m \(\) <++><Esc>F(a
autocmd     BufNewFile,BufRead *.tex inoremap ;M \[\]<CR><CR><++><Esc>?[<CR>a<CR><Esc>O
autocmd     BufNewFile,BufRead *.tex inoremap ;bf \textbf{}<Space><++><Esc>F{a
autocmd     BufNewFile,BufRead *.tex inoremap ;it \textit{}<Space><++><Esc>F{a
autocmd     BufNewFile,BufRead *.tex inoremap ;un \underline{}<Space><++><Esc>F{a
autocmd     BufNewFile,BufRead *.tex vnoremap <Space><Space> "wdi\(\)<Esc>2h"wp


" Html things.
"
autocmd     BufNewFile,BufRead *.html inoremap ;ht <html><CR></html><Esc>O
autocmd     BufNewFile,BufRead *.html inoremap ;he <head><CR></head><CR><CR><Space><++><Esc>?><CR>O
autocmd     BufNewFile,BufRead *.html inoremap ;bo <body><CR></body><CR><CR><Space><++><Esc>?><CR>O
autocmd     BufNewFile,BufRead *.html inoremap ;di <div><CR></div><CR><Space><++><Esc>?><CR>O
autocmd     BufNewFile,BufRead *.html inoremap ;dc <div class=''><CR><Space><++><CR></div><CR><Space><++><Esc>?'<CR>i
autocmd     BufNewFile,BufRead *.html inoremap ;b <b></b><Space><++><Esc>FbT>i
autocmd     BufNewFile,BufRead *.html inoremap ;i <em></em><++><Esc>FeT>i
autocmd     BufNewFile,BufRead *.html inoremap ;h1 <h1> </h1><CR><CR><Space><++><Esc>2kf<Space>s
autocmd     BufNewFile,BufRead *.html inoremap ;h2 <h2> </h2><CR><CR><Space><++><Esc>2kf<Space>s
autocmd     BufNewFile,BufRead *.html inoremap ;h3 <h3> </h3><CR><CR><Space><++><Esc>2kf<Space>s
autocmd     BufNewFile,BufRead *.html inoremap ;h4 <h4> </h4><CR><CR><Space><++><Esc>2kf<Space>s
autocmd     BufNewFile,BufRead *.html inoremap ;p <p><CR></p><CR><CR><Space><++><Esc>?><CR>O
autocmd     BufNewFile,BufRead *.html inoremap ;a <a<Space>href=''><++></a><Space><++><Esc>F'i
autocmd     BufNewFile,BufRead *.html inoremap ;im <img<Space>src=''/><Space><++><Esc>F'i
autocmd     BufNewFile,BufRead *.html inoremap ;ul <ul><CR><li></li><Space><++><CR></ul><CR><CR><Space><++><Esc>03kf<;i
autocmd     BufNewFile,BufRead *.html inoremap ;ol <ol><CR><li></li><Space><++><CR></ol><CR><CR><Space><++><Esc>03kf<;i
autocmd     BufNewFile,BufRead *.html inoremap ;li <Esc>o<li></li><Space><++><Esc>F>;a


" EOF

